﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.Configuration;
using System.Data.Services.Client;
using TGIApp.Model;

namespace TGIApp.Web.Controllers
{
    public class RoleController : Controller
    {
        //
        // GET: /Role/

        public ActionResult Index()
        {
            var proxy = new Proxy.ServiceProxy();
            var roles = proxy.GetAllRoles();
            return View(roles);
        }

        //
        // GET: /Role/Details/5

        public ActionResult Details(int id)
        {
            var proxy = new Proxy.ServiceProxy();
            var role = proxy.GetRoleById(id);
            return View(role);
        }

        //
        // GET: /Role/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Role/Create

        [HttpPost]
        public ActionResult Create(Role role)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.CreateRole(role);
            }
            return RedirectToAction("Index");
        }
        
        //
        // GET: /Role/Edit/5
 
        public ActionResult Edit(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var role = proxy.GetRoleById(id);
            return View(role);
        }

        //
        // POST: /Role/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, Role updatedRole)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.UpdateRole(updatedRole);
            }
            return RedirectToAction("Index");
        }

        //
        // GET: /Role/Delete/5
 
        public ActionResult Delete(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var role = proxy.GetRoleById(id);
            return View(role);
        }

        //
        // POST: /Role/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, Role roleToBeDeleted)
        {

            ITgiService proxy = new Proxy.ServiceProxy();
            proxy.DeleteRoleById(id);
            return RedirectToAction("Index");
        }
    }
}
